﻿using System;
using System.Diagnostics;

namespace MikeKappel.Com.CS
{
    public static partial class SortingAlgorithms
    {
        public delegate Boolean InPlaceMergeDelegate(Int32 currentIndex, Int32 currentValue);

        public static void InPlaceMergeSort(InPlaceMergeDelegate onSort, Int32[] items)
        {
            //Int32[] result = new Int32[items.Length];
            //Int32 middle = (Int32)Math.Ceiling(items.Count / 2);
            //Int32[] leftArray = items.GetRange(0, middle);
            //Int32[] rightArray = items.GetRange(middle, items.Count - middle);
            //leftArray = MergeSort(leftArray);
            //rightArray = MergeSort(rightArray);
            //int leftptr = 0;
            //int rightptr = 0;
            //for (int i = 0; i < leftArray.Count + rightArray.Count; i++)
            //{
            //    if (leftptr == leftArray.Count)
            //    {
            //        arrSortedInt.Add(rightArray[rightptr]);
            //        rightptr++;
            //    }
            //    else if (rightptr == rightArray.Count)
            //    {
            //        arrSortedInt.Add(leftArray[leftptr]);
            //        leftptr++;
            //    }
            //    else if ((int)leftArray[leftptr] < (int)rightArray[rightptr])
            //    {
            //        //need the cast above since arraylist returns Type object
            //        arrSortedInt.Add(leftArray[leftptr]);
            //        leftptr++;
            //    }
            //    else
            //    {
            //        arrSortedInt.Add(rightArray[rightptr]);
            //        rightptr++;
            //    }
            //}
            //return arrSortedInt;

        }
        public static void InPlaceMergeSort(Int32[] items)
        {
            InPlaceMergeSort(null, items);
        }
    }
}
